//
//  UIView+FrameExt.m
//  ContinueEducation
//
//  Created by cjg.mini on 2018/7/10.
//  Copyright © 2018年 CE. All rights reserved.
//

#import "UIView+FrameExt.h"

@implementation UIView (FrameExt)

- (void)removeViewWithTag:(NSInteger)tag {
    [[self viewWithTag:tag] removeFromSuperview];
}

- (void)setCe_size:(CGSize)ce_size{
    CGPoint origin = [self frame].origin;
    
    [self setFrame:CGRectMake(origin.x, origin.y, ce_size.width, ce_size.height)];
    
}

- (CGSize)ce_size
{
    return [self frame].size;
}

-(CGFloat)ce_x
{
    return self.frame.origin.x;
}

-(void)setCe_x:(CGFloat)ce_x
{
    CGRect frame = self.frame;
    frame.origin.x = ce_x;
    self.frame = frame;
}

-(CGFloat)ce_y
{
    return self.frame.origin.y;
}

-(void)setCe_y:(CGFloat)ce_y
{
    CGRect frame = self.frame;
    frame.origin.y = ce_y;
    self.frame = frame;
}


-(CGFloat)ce_width
{
    return self.frame.size.width;
}

-(void)setCe_width:(CGFloat)ce_width
{
    CGRect frame = self.frame;
    frame.size.width = ce_width;
    self.frame = frame;
}


-(CGFloat)ce_height
{
    return self.frame.size.height;
}

-(void)setCe_height:(CGFloat)ce_height
{
    CGRect frame = self.frame;
    frame.size.height = ce_height;
    self.frame = frame;
}


-(CGFloat)ce_centerX
{
    return self.center.x;
}

-(void)setCe_centerX:(CGFloat)ce_centerX
{
    CGPoint center = self.center;
    center.x = ce_centerX;
    self.center = center;
}


-(CGFloat)ce_centerY
{
    return self.center.y;
}

-(void)setCe_centerY:(CGFloat)ce_centerY
{
    CGPoint center = self.center;
    center.y = ce_centerY;
    self.center = center;
}

-(CGFloat)right
{
    return CGRectGetMaxX([self frame]);
}

-(void)setRight:(CGFloat)right
{
    CGRect frame = [self frame];
    frame.origin.x = right - frame.size.width;
    
    [self setFrame:frame];
}


- (CGFloat)left
{
    return CGRectGetMinX([self frame]);
}

- (void)setLeft:(CGFloat)x
{
    CGRect frame = [self frame];
    frame.origin.x = x;
    [self setFrame:frame];
}

- (CGFloat)top
{
    return CGRectGetMinY([self frame]);
}

- (void)setTop:(CGFloat)y
{
    CGRect frame = [self frame];
    frame.origin.y = y;
    [self setFrame:frame];
}

- (CGFloat)bottom
{
    return CGRectGetMaxY([self frame]);
}

- (void)setBottom:(CGFloat)bottom
{
    CGRect frame = [self frame];
    frame.origin.y = bottom - frame.size.height;
    
    [self setFrame:frame];
}

- (void)removeAllSubviews
{
    while (self.subviews.count)
    {
        UIView *child = self.subviews.lastObject;
        [child removeFromSuperview];
    }
}

@end
